﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;

namespace ConsoleApp3
{
    public enum NPCRole
    {
        刘备 = 1,
        孙权 ,
        曹操 
    }
    public enum Fist
    {
        石头 = 1,
        剪刀 ,
        布 
    }
    class Program
    {
        static JudgeMan jm = new JudgeMan();
        static Player p = new Player();
        static NPCMan npc = new NPCMan();
        static int count = 0;
        static int pCount = 0;
        static int nCount = 0;

        static void Main(string[] args)
        {
            PlayFistGame();
        }

        private static void PlayFistGame()
        {
            Welcome();
            Prepare();
            Battle();
            ShowResult();
        }

        Console.WriteLine(".....................................................................");
        private static void Welcome()
        {
            Console.WriteLine("====================......欢 迎 进 入 游 戏的 世 界...........====================\r\n");
            Console.WriteLine("************************************");
            Console.WriteLine("*************猜拳，开始啦啦啦！！！*************");
            Console.WriteLine("************************************\r\n");
        }

        private static void Prepare()
        {
            while (true)
            {
                Console.WriteLine("出拳规则：{0}", ListFist()); ;
                Console.WriteLine("请选择对方角色：{0}", ListNPC());
                int num = int.Parse(Console.ReadLine());
                npc.Name = ((NPCRole)num).ToString();

                Console.WriteLine("请输入您的姓名：");
                p.Name = Console.ReadLine();

                Console.WriteLine("{0} VS {1}  对战", p.Name, npc.Name);
                Console.WriteLine("开始游戏吗？（y/n）");
                string key = Console.ReadLine();
                if (key == "y")
                {
                    break;
                }
            }
        }
        Console.WriteLine(".....................................................................");

        private static void Battle()
        {
            while (true)
            {
                Console.WriteLine("\n\r请出拳：{0}", ListFist());
                int pf = p.ShowFist();
                int nf = npc.ShowFist();
                Console.WriteLine("\r\n{0}  出：  {1}", p.Name, (Fist)pf);
                Console.WriteLine("{0}  出：  {1}", npc.Name, (Fist)nf);
                int result = IsWin(pf, nf);

                Console.WriteLine();
                Console.WriteLine(result == 0 ? "不可思议鸭，平局啦！！！" : result == 1 ? $"恭喜恭喜恭喜！！！{p.Name}赢了！" : $"太不好意思了！{p.Name}输了！");

                count++;
                if (result == 1)
                {
                    pCount++;
                }
                else if (result == -1)
                {
                    nCount++;
                }

                Console.WriteLine("是否开始下一轮的猜拳活动呢？（y/n）");
                string key = Console.ReadLine();
                if (key != "y")
                {
                    break;
                }
            }
        }

        static void ShowResult()
        {
            Console.WriteLine("====================================================");
            Console.WriteLine("{0} VS {1}", p.Name, npc.Name);
            Console.WriteLine("对战次数：{0}", count);
            Console.WriteLine("姓名\t得分");
            Console.WriteLine("{0}\t{1}", p.Name, pCount);
            Console.WriteLine("{0}\t{1}", npc.Name, nCount);
            Console.WriteLine("平局\t{0}", count-nCount-pCount);
            Console.WriteLine("总结果：" + (pCount > nCount ? p.Name : npc.Name) + "吼吼！！！赢了鸭鸭鸭！");
            Console.WriteLine("是否开始下一局的游戏呢？（y/n）");
            string key = Console.ReadLine();
            if (key == "y")
            {
            	count = 0;
          		pCount = 0;
                nCount = 0;
                PlayFistGame();
            }
            else
            {
                Console.WriteLine("系统要退出了！！！");
            }
        }
        Console.WriteLine(".....................................................................");
        

        private static int IsWin(int pf, int nf)
        {
            if (pf == nf)
            {
                return 0;
            }
            else if (pf == 1 && nf == 2 || pf == 2 && nf == 3 || pf == 3 && nf == 1)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }

        static string ListFist()
        {
            string fistStr = "";
            foreach (Fist f in Enum.GetValues(typeof(Fist)))
            {
                fistStr += (int)f + "、" + f + "；";
            }
            return fistStr;
        }
        Console.WriteLine(".....................................................................");
        static string ListNPC()
        {
            string roleStr = "";
            foreach (NPCRole n in Enum.GetValues(typeof(NPCRole)))
            {
                roleStr += (int)n + "、" + n + "；";
            }
            return roleStr;
        }

    }
}
